
###*
 # @ngdoc function
 # @name xoceanApp.controller:ModuleCtrl
 # @description
 # # ModuleCtrl
 # Controller of the choose module dialog
###
angular.module('xoceanApp')
  .controller 'ModuleCtrl', ($rootScope, $scope, $filter, Module) ->
    $scope.modules = Module.getModules()

    for mod, i in $scope.modules
      if $scope.modules[i].url is 'module.aside'
        $scope.modules[i].usable = $scope.child
      else
        $scope.modules[i].usable = !$scope.child
    if $scope.child
      $scope.currentTab = 'module.aside'
    else
      $scope.currentTab = 'module.photoset'

    $scope.subModules = $filter('filter')($scope.modules, {url: $scope.currentTab})[0]['subModules']
    $scope.isActiveTab = (url)->
      return $scope.currentTab is url
    $scope.onClickTab = (mod)->
      return if mod.usable is false and mod.url isnt 'module.custom'
      $scope.currentTab = mod.url
      unless mod.url is 'module.costom'
        $scope.subModules = $filter('filter')($scope.modules, {url: $scope.currentTab})[0]['subModules']

      return

    
    return
